home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Graphismes / Bitmap / NIH Image 1.59 / Macros / Gel Plotting Macros < prev    next >
Text File  |  1994-05-27  |  6KB  |  217 lines

  1. var  {Global variables}
  2.   RoiLeft,RoiTop,RoiWidth,RoiHeight:integer;
  3.   GelPid,MarkedPid,nLanes,count,ppv:integer;
  4.   SaveRoiLeft,SaveRoiTop,hOffset,vOffset:integer;
  5.   MinY,MaxY,xscale,yscale:real;
  6.   VerticalLanes,Uncalibrated:boolean;
  7.  
  8. procedure MarkLane;
  9. var
  10.   left,top,width,height:integer;
  11.   GelNotCalibrated:boolean;
  12.   min,max:real;
  13. begin
  14.   GetRoi(left,top,width,height);
  15.   if width=0 then begin
  16.     PutMessage('Please outline the next lane.');
  17.     exit;
  18.   end;
  19.   if (VerticalLanes and (left=RoiLeft))
  20.       or  (not VerticalLanes and (top=RoiTop)) then begin
  21.      PutMessage('This lane has already been marked.');
  22.      exit;
  23.   end;
  24.   nLanes:=nLanes+1;
  25.   ChoosePic(GelPid);
  26.   if VerticalLanes then begin
  27.      MakeRoi(left+hOffset,RoiTop+vOffset,RoiWidth,RoiHeight);
  28.      RoiLeft:=left;
  29.      rUser1[nLanes]:=left;
  30.   end else begin
  31.      MakeRoi(RoiLeft+hOffset,top+vOffset,RoiWidth,RoiHeight);
  32.      RoiTop:=top;
  33.      rUser1[nLanes]:=top;
  34.   end;
  35.   GetPlotData(count,ppv,min,max);
  36.   if min<MinY then MinY:=min;
  37.   if max>MaxY then MaxY:=max;
  38.   SelectPic(MarkedPid);
  39.   if VerticalLanes
  40.      then MakeRoi(left,RoiTop,RoiWidth,RoiHeight)
  41.      else MakeRoi(RoiLeft,top,RoiWidth,RoiHeight);
  42.   DrawBoundary;
  43.   SetFontSize(9);
  44.   if VerticalLanes then begin
  45.     SetText('Centered, No Background');
  46.     MoveTo(RoiLeft+RoiWidth/2,RoiTop-6);
  47.   end else begin
  48.     SetText('Right Justified, No Background');
  49.     MoveTo(RoiLeft-2,RoiTop+RoiHeight/2);
  50.   end;
  51.   Write(nLanes:1);
  52.   RestoreRoi;
  53.   SelectPic(MarkedPid);
  54. end;
  55.  
  56.  
  57. macro 'Mark First Lane [1]';
  58. var
  59.   GelWidth,GelHeight,left,width:integer;
  60.   margin,leftm,rightm,topm,bottomm:integer;
  61. begin
  62.   RequiresVersion(1.54);
  63.   if WindowTitle='Temp' then begin
  64.     PutMessage('To restart, select the first lane in the gel.');
  65.     exit;
  66.   end;
  67.   GetRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight);
  68.   if RoiWidth=0 then begin
  69.     PutMessage('The Setup macro expects the Gel to be displayed and the first lane outlined.');
  70.     exit;
  71.   end;
  72.   VerticalLanes:=RoiHeight>RoiWidth;
  73.   Uncalibrated:=not Calibrated;
  74.   GelPid:=PidNumber;
  75.   SetForegroundColor(255);
  76.   SetBackgroundColor(0);
  77.   MinY:=999999;
  78.   MaxY:=-999999;
  79.   nLanes:=0;
  80.   margin:=20;
  81.   GetPicSize(GelWidth,GelHeight);
  82.   leftm:=RoiLeft;
  83.   if leftm>margin then leftm:=margin;
  84.   rightm:=GelWidth-(RoiWidth+RoiLeft);
  85.   if rightm>margin then rightm:=margin;
  86.   bottomm:=GelHeight-(RoiHeight+RoiTop);
  87.   if bottomm>margin then bottomm:=margin;
  88.   topm:=RoiTop;
  89.   if topm>margin then topm:=margin;
  90.   if VerticalLanes
  91.     then MakeRoi(RoiLeft-leftm,RoiTop-topm,
  92.            GelWidth-RoiLeft+leftm,RoiHeight+topm+bottomm)
  93.     else MakeRoi(RoiLeft-leftm,RoiTop-topm,
  94.            RoiWidth+leftm+rightm,GelHeight-RoiTop+topm);
  95.   Duplicate('Temp');
  96.   MarkedPid:=PidNumber;
  97.   SaveRoiLeft:=RoiLeft;
  98.   SaveRoiTop:=RoiTop;
  99.   hOffset:=RoiLeft-leftm;
  100.   vOffset:=RoiTop-topm;
  101.   RoiLeft:=leftm;
  102.   RoiTop:=topm;
  103.   SelectPic(GelPid);
  104.   KillRoi;
  105.   SelectPic(MarkedPid);
  106.   MakeRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight);
  107.   if VerticalLanes
  108.     then RoiLeft:=-1
  109.     else RoiTop:=-1;
  110.   SetPlotScale(0,0);
  111.   MarkLane;
  112. end;
  113.  
  114. macro 'Mark Next Lane [2]';
  115. var
  116.   left,top,width,height:integer;
  117.   GelNotCalibrated:boolean;
  118.   min,max:real;
  119. begin
  120.   if nLanes=0 then begin
  121.     PutMessage('Please use the "Mark First Lane" macro first.');
  122.     Exit;
  123.   end;
  124.   MarkLane;
  125. end;
  126.  
  127. macro 'Plot Lanes [3]';
  128. var
  129.   left,top,width,height:integer;
  130.   GelNotCalibrated:boolean;
  131.   i,LaneLength:integer;
  132.   xmin,xmax,ymin,ymax,min,max:real;
  133.   MaxPlotWindowHeight,NeededSize:integer;
  134.   PlotTop,PlotBottom,PlotWidth,PlotHeight:integer;
  135.   hMargin,vMargin,SavePlotTop,PlotWindowSize:integer;
  136.   PlotWinHeight,PlotWinWidth,PlotsPid:integer;
  137. begin
  138.   if nLanes=0 then begin
  139.     PutMessage('Please use the Setup and Mark macros first.');
  140.     Exit;
  141.   end;
  142.   if VerticalLanes
  143.     then LaneLength:=RoiHeight
  144.     else LaneLength:=RoiWidth;
  145.   PlotWidth:=LaneLength;
  146.   if PlotWidth<500 then PlotWidth:=500;
  147.   if PlotWidth>(2*LaneLength) then PlotWidth:=2*LaneLength;
  148.   PlotHeight:=PlotWidth/2;
  149.   if PlotHeight<200 then PlotHeight:=200;
  150.   if PlotHeight>400 then PlotHeight:=400;
  151.   MaxPlotWindowHeight:=800;
  152.   hMargin:=5;
  153.   vMargin:=5;
  154.   PlotWinHeight:=nLanes*PlotHeight+2*vMargin;
  155.   if PlotWinHeight>MaxPlotWindowHeight then begin
  156.      PlotWinHeight:=MaxPlotWindowHeight;
  157.      PlotHeight:=(PlotWinHeight-2*vMargin)/nLanes;
  158.   end;
  159.   PlotWinWidth:=PlotWidth+2*hMargin;
  160.   PlotWindowSize:=PlotWinWidth*PlotWinHeight;
  161.   if PlotWindowSize>UndoBufferSize then begin
  162.     NeededSize:=(PlotWindowSize+0.05*PlotWindowSize) div 1024;
  163.     PutMessage('Use Preferences(Options Menu) to increase the Undo buffer size to at least ',NeededSize:1,'K.');
  164.     KillRoi;
  165.     exit;
  166.   end;
  167.   SetForegroundColor(255);
  168.   SetBackgroundColor(0);
  169.   SetNewSize(PlotWinWidth,PlotWinHeight);
  170.   MakeNewWindow('Plots');
  171.   PlotsPid:=PidNumber;
  172.   if UnCalibrated then begin
  173.     SetText('Left Justified');
  174.     SetFontSize(12);
  175.     MoveTo(6,vmargin+1);
  176.     Write('uncalibrated');
  177.   end;
  178.   xmin:=0;
  179.   xmax:=count-1;
  180.   ymin:=MinY;
  181.   ymax:=MaxY;
  182.   xscale:=PlotWidth/(xmax-xmin);
  183.   yscale:=PlotHeight/(ymax-ymin);
  184.   PlotTop:=vMargin;
  185.   SavePlotTop:=PlotTop;
  186.   RoiLeft:=SaveRoiLeft;
  187.   RoiTop:=SaveRoiTop;
  188.   SetLineWidth(1);
  189.   for i:=1 to nLanes do begin
  190.      PlotBottom:=PlotTop+(ymax-ymin)*yscale;
  191.      ChoosePic(GelPid);
  192.      if VerticalLanes
  193.         then MakeRoi(rUser1[i]+hOffset,RoiTop,RoiWidth,RoiHeight)
  194.         else MakeRoi(RoiLeft,rUser1[i]+vOffset,RoiWidth,RoiHeight);
  195.      GetPlotData(count,ppv,min,max);
  196.      SelectPic(PlotsPid);
  197.      MoveTo(hMargin,PlotBottom);
  198.      LineTo(PlotWinWidth-hMargin,PlotBottom);
  199.      MoveTo(hMargin,PlotBottom-(PlotData[0]-ymin)*yscale);
  200.      for i:=1 to count-1 do
  201.         LineTo(hMargin+i*xscale,PlotBottom-(PlotData[i]-ymin)*yscale);
  202.      PlotTop:=PlotTop+PlotHeight;
  203.   end;
  204.   nLanes:=0;
  205.   ResetCounter;
  206.   SetOptions('Area');
  207.   WandAutoMeasure(true);
  208.   AdjustAreas(true);
  209.   LabelParticles(false);
  210.   IncludeInteriorHoles(true);
  211.   SetFontSize(9);
  212.   SetText('Centered');
  213.   if Uncalibrated
  214.     then SetScale(0,'pixels')
  215.     else SetScale(sqrt(xscale*yscale/ppv),'unit');
  216. end;
  217.